package com.example.LibrarySystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.LibrarySystem.pojo.Inventory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface InventoryMapper extends BaseMapper<Inventory> {

    @Update("update inventory set number = #{number} where book_id = #{id}")
    public int updateNumberById(int number, int id);

    /**
     * 根据书本id 让库存减1
     */
    @Update("update inventory set number = number - 1 where book_id = #{bookId}")
    public int updateNumberByMinus(int bookId);

    /**
     * 根据书本id 让库存加1
     */
    @Update("update inventory set number = number + 1 where id = #{id}")
    public int updateNumberByAdd(int id);

    /**
     * 根据借书id 让库存加1
     */
    @Update("update inventory set number = number + 1 where id = #{id}")
    public int updateNumberByIdAndAdd(int bookId);

}
